<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'JSONP.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
		
	<script type="text/javascript">
     //添加<script>标签的方法
     function addScriptTag(src){
         var script = document.createElement('script');
         script.setAttribute("type","text/javascript");
         script.src = src;
         document.body.appendChild(script);
     }
     
     window.onload = function(){
         //搜索apple，将自定义的回调函数名result传入callback参数中
         //addScriptTag("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=apple&callback=result");
         addScriptTag("http://www.geonames.org/postalCodeLookupJSON?postalcode=10504&country=US&callback=result");
         
     }
     //自定义的回调函数result
     function result(data) {
         //我们就简单的获取apple搜索结果的第一条记录中url数据
        // alert(data.responseData.results[0].unescapedUrl);
        alert(data.postalcodes);
     }
 </script>
  </head>
  
  <body>
    This is my JSP page. <br>
  </body>
</html>
